package com.jt.service;/**
 * @Author 金帮嘉诚 @Date 2021-08-04 星期三 10:55
 */
/*本类用于测试*/

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 知识点
 */
@Service
public class RightsServiceImpl implements RightsService {
    @Autowired
    private RightsMapper rightsMapper;

    /*自己的方法*/

    /**
     * 获取rights表 注意级别
     */
    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
        //获得一级菜单信息
        List<Rights> rightsList = new ArrayList<>();
        queryWrapper.eq("parent_id", 0);
        rightsList = rightsMapper.selectList(queryWrapper);
        //二级菜单
        //遍历得到每个项目的children 并放入该列
        for (Rights r1 : rightsList
        ) {
            queryWrapper.clear();
            queryWrapper.eq("parent_id", r1.getId());
            List<Rights> childrenRightsList = rightsMapper.selectList(queryWrapper);
            r1.setChildren(childrenRightsList);
        }

        //三级菜单
//        for (Rights r1 : rightsList
//        ) {
//            for (Rights r2 : r1.getChildren()
//            ) {
//                queryWrapper.clear();
//                queryWrapper.eq("parent_id", r2.getId());
//                List<Rights> childrenRightsList = rightsMapper.selectList(queryWrapper);
//                r2.setChildren(childrenRightsList);
//            }
//        }

        return rightsList;
    }
}
